<!--
 * @Author: Bennty
 * @Date: 2024-07-25 16:44:45
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2024-09-20 16:19:05
 * @Description: 请填写简介
-->
<template>
    <el-dialog v-model="props.visible" title="样品审批" @close="handleClose" destory-on-close>
        <el-form>
            <el-form-item label="客户名称">
                <span>{{ props.data.customerName }}</span>
            </el-form-item>
            <el-form-item label="客户体量">
                <span class="level-one" v-if="props.data.level == '1'">一级客户</span>
                <span class="level-two" v-else-if="props.data.level == '2'">二级客户</span>
                <span class="level-three" v-else-if="props.data.level == '3'">三级客户</span>
                <span class="level-four" v-else-if="props.data.level == '4'">四级客户</span>
                <span class="level-five" v-else-if="props.data.level == '5'">五级客户</span>
            </el-form-item>
            <el-form-item label="成交状态">
                <span class="done" v-if="props.data.status">已成交</span>
                <span class="undone" v-else>未成交</span>
            </el-form-item>
            <el-form-item label="申请来源">
                {{ props.sources.filter((item:any)=>item.value == props.data.applySource)[0]?.label }}
            </el-form-item>
            <el-form-item label="关联订单编号">
                <span>{{ props.data.orderNumber }}</span>
            </el-form-item>
            <el-form-item label="申请样品名称">
                <span>{{ props.data.welfareName }}</span>
            </el-form-item>
            <el-form-item label="申请样品数量">
                <span>{{ props.data.applyNum}}</span>
            </el-form-item>
            
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button  type="primary" @click="handlePassApply" >通过</el-button>
                <el-button type="danger" @click="handleRejectApply">拒绝</el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import type { FormInstance } from 'element-plus';
import { applyWelfareApi } from '@/api/sj/welfareExamine-crm/index';

const props = defineProps(['visible','data','sources']);
const emits = defineEmits(['close','submit']);
const formRef = ref<FormInstance>();

const handlePassApply = async () => {
    const submitData = {
        id: props.data.id,
        approvalStatus: 2
    };
    const result = await applyWelfareApi(submitData);
    if(result.code == 200){
        emits('submit',true);
        handleClose();
    }else{
        emits('submit',false);
    };
};

const handleRejectApply = async () => {
    const submitData = {
        id: props.data.id,
        approvalStatus: 3
    };
    const result = await applyWelfareApi(submitData);
    if(result.code == 200){
        emits('submit',true);
        handleClose();
    }else{
        emits('submit',false);
    };
};

const handleClose = ()=>{
    formRef.value?.resetFields();
    emits('close');
};
</script>

<style lang="scss" scoped>
.level-one,.level-two {
    color:yellowgreen
}
.level-three,.level-four{
    color: orange;
}
.level-five{
    color: red
}
.done{
    color: yellowgreen
}
.undone{
    color: orange
}
.dialog-footer{
    display: flex;
    justify-content: center;
}
</style>